package com.example.myapplication;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TimePicker;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import java.util.Calendar;

public class CustomDateTimePickerDialog extends DialogFragment {

    private OnDateTimeSetListener mListener;

    public interface OnDateTimeSetListener {
        void onDateTimeSet(Calendar dateTime);
    }

    public static CustomDateTimePickerDialog newInstance(OnDateTimeSetListener listener) {
        CustomDateTimePickerDialog dialog = new CustomDateTimePickerDialog();
        dialog.mListener = listener;
        return dialog;
    }

//    @NonNull
//    @Override
//    public Dialog onCreateDialog(Bundle savedInstanceState) {
//        Context context = requireContext();
//        View view = LayoutInflater.from(context).inflate(R.layout.custom_date_time_picker_dialog, null);
//
//        // 初始化当前日期和时间
//        Calendar calendar = Calendar.getInstance();
//
//        // 创建自定义对话框
//        AlertDialog.Builder builder = new AlertDialog.Builder(context)
//                .setTitle("选择日期和时间")
//                .setPositiveButton("确认", (dialogInterface, i) -> {
//                    if (mListener != null) {
//                        DatePicker datePicker = view.findViewById(R.id.date_picker);
//                        TimePicker timePicker = view.findViewById(R.id.time_picker);
//
//                        int year = datePicker.getYear();
//                        int month = datePicker.getMonth();
//                        int dayOfMonth = datePicker.getDayOfMonth();
//                        int hourOfDay = timePicker.getCurrentHour();
//                        int minute = timePicker.getCurrentMinute();
//
//                        // 更新并返回选择的日期和时间
//                        calendar.set(year, month, dayOfMonth, hourOfDay, minute);
//                        mListener.onDateTimeSet(calendar);
//                    }
//                })
//                .setNegativeButton("取消", null);
//
//        // 加载自定义布局
////        View view = LayoutInflater.from(context).inflate(R.layout.custom_date_time_picker_dialog, null);
//        builder.setView(view);
//
//        // 初始化并设置日期选择器
//        DatePicker datePicker = view.findViewById(R.id.date_picker);
//        datePicker.init(
//                calendar.get(Calendar.YEAR),
//                calendar.get(Calendar.MONTH),
//                calendar.get(Calendar.DAY_OF_MONTH),
//                null
//        );
//
//        // 初始化并设置时间选择器
//        TimePicker timePicker = view.findViewById(R.id.time_picker);
//        timePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
//        timePicker.setCurrentMinute(calendar.get(Calendar.MINUTE));
//
//        return builder.create();
//    }
}